package kii.events
{
	/**
	 * <code>ResultEvent</code> is dispatched by <code>IService</code> implementros.
	 * @author David "Nirth" Sergey
	 */
	public class ResultEvent extends KiiEvent
	{
		static public const RESULT:String = 'result';
		/**
		 * Constructs new <code>ResultEvent</code> instance.
		 * @param type   Event type.
		 * @param result Operation Result.
		 */
		public function ResultEvent(type:String, result:Object = null, url:String = null)
		{
			super(type);
			_result = result;
			_url = url;
		}
		/**
		 * @private
		 */
		private var _url:String;
		/**
		 * URL of the <code>Operation</code> that returned <code>ResultEvent</code> method.
		 */
		public function get url():String
		{
			return _url;
		}
		/**
		 * Last part of the URL that represents operation.
		 */
		public function get operation():String
		{
			return _url.split('/').reverse()[0];
		}
		/**
		 * @private
		 */
		private var _result:Object;
		public function get result():Object
		{
			return _result;
		}
		/**
		 * Returns converted to <code>XML</code> <code>ResultEvent.result</code> object.
		 */
		public function get xml():XML
		{
			return XML(_result);
		}
		/**
		 * @inheritDoc
		 */
		override public function toString():String
		{
			return formatToString('ResultEvent', 'type', 'result');
		}
		
	}
}